package com.wangsd.web.face.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wangsd.web.face.entity.CloseAccount;
import com.wangsd.web.face.mapper.CloseAccountMapper;
import com.wangsd.web.face.service.CloseAccountService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author generator
 * @since 2019-11-20
 */
@Service
public class CloseAccountServiceImpl extends ServiceImpl<CloseAccountMapper, CloseAccount> implements CloseAccountService {

    @Resource
    CloseAccountMapper closeAccountMapper;

    @Override
    public CloseAccount selectByFirst(String deviceNo) {
        QueryWrapper<CloseAccount> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("device_no", deviceNo);
        queryWrapper.orderByDesc("created_time");
        List<CloseAccount> closeAccounts = closeAccountMapper.selectList(queryWrapper);
        if (closeAccounts != null && closeAccounts.size() > 0) {
            return closeAccounts.get(0);
        }
        return null;
    }

    @Override
    public IPage<CloseAccount> selectList(Integer pageSize, Integer pageNum, CloseAccount closeAccount) {
        Page<CloseAccount> page = new Page<>(pageNum, pageSize);
        QueryWrapper<CloseAccount> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("device_no", closeAccount.getDeviceNo());
        queryWrapper.eq("store_user_id", closeAccount.getStoreUserId());
        queryWrapper.orderByDesc("created_time");
        IPage<CloseAccount> closeAccountIPage = closeAccountMapper.selectPage(page, queryWrapper);
        return closeAccountIPage;
    }
}
